from rest_framework import serializers
from shops.serializers import ShopsSerializer
from goods.serializers import FoodSerializer

from cart.models import CartModel


class CartSerializer(serializers.ModelSerializer):
    shop = ShopsSerializer()
    foods = FoodSerializer()

    class Meta:
        model = CartModel
        fields = '__all__'

    def to_representation(self, instance):
        data = super().to_representation(instance)
        data['shop'] = data.pop('shop')
        data['foods'] = data.pop('foods')
        return data
